<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index extends Controller
{
    public function index()
    {
        //连接数据表，查询数据
        $data = Db::name('nvg')->select();
        $this->assign('data',$data);

        $prod = Db::name('product_cate')->select();
        $product = Db::name('product')->select();
        $arr=[];
        foreach ($product as &$v){
            $arr[$v['product_cate_id']][]=$v;
        }
        foreach ($prod as &$value){
            $value['son']=$arr[$value['id']]??[];
        }
        $this->assign('prod',$prod);

        $newscate = Db::name('news_cate')->select();
        $news = Db::name('news')->select();
        $arr=[];
        foreach ($news as &$v){
            $arr[$v['news_cate_id']][]=$v;
        }
        foreach ($newscate as &$value){
            $value['son']=$arr[$value['id']]??[];
        }
        $this->assign('newscate',$newscate);

        $system = Db::name('system')->select();
        $new = Db::name('news')->field('id,title,thumb,content,tag')->select();
        $banner = Db::name('banner')->select();
        //打印出数组，变量名，传递的
        $this->assign('banner',$banner);
        $this->assign('prod',$prod);
        $this->assign('news',$news);

        $this->assign('system',$system);
        $this->assign('new',$new);
        return view('index');
        //return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> Tplay<br/><span style="font-size:30px">为开发者量身定制的高速度开发后台管理框架</span></p><span style="font-size:22px;"><br>【重要】【重要】【重要】Tplay后台管理框架目前没有开发index前台模块，请严格按照安装包中的安装说明进行安装！！';
    }
    public function pro()
    {
       @ $id=$_GET['id'];
        if ($id){
            $data = Db::name('nvg')->select();
            $this->assign('data',$data);

            $prod = Db::name('product_cate')->select();
            $product = Db::name('product')->where(['product_cate_id'=>$id])->select();
            $arr=[];
            foreach ($product as &$v){
                $arr[$v['product_cate_id']][]=$v;
            }
            foreach ($prod as &$value){
                $value['son']=$arr[$value['id']]??[];
            }
            $this->assign('prod',$prod);

            return view('pro');
        }
        $data = Db::name('nvg')->select();
        $this->assign('data',$data);

        $prod = Db::name('product_cate')->select();
        $product = Db::name('product')->select();
        $arr=[];
        foreach ($product as &$v){
            $arr[$v['product_cate_id']][]=$v;
        }
        foreach ($prod as &$value){
            $value['son']=$arr[$value['id']]??[];
        }
        $this->assign('prod',$prod);

        return view('pro');
    }
    public function news()
    {
        $news = Db::name('news')->select();
        $newscate = Db::name('news_cate')->select();
        $data = Db::name('nvg')->select();
        $this->assign('data',$data);
        $this->assign('news',$news);
        $this->assign('newscate',$newscate);
        return view('news');
    }
    public function contact()
    {
        $contact = Db::name('contact')->select();
        $this->assign('contact',$contact);
        $data = Db::name('nvg')->select();
        $this->assign('data',$data);
        return view('contact');
    }
    public function job()
    {
        $ne = Db::name('news')->field('id,title,content,create_time')->select();
        $data = Db::name('nvg')->select();
        $this->assign('data',$data);
        $this->assign('ne',$ne);
        return view('job');
    }
    public function pro_more()
    {
        $id=$_GET['id'];
        $product = Db::name('product')->where(['id'=>$id])->select();
        $data = Db::name('nvg')->select();
        $this->assign('product',$product);
        $this->assign('data',$data);
        $this->assign('nvg',$data);
        return view('pro_more');
    }
    public function pro_mord()
    {
       $id=$_GET['id'];
        $new = Db::name('news')->where(['id'=>$id])->select();
        $data = Db::name('nvg')->select();
        $this->assign('new',$new);
        $this->assign('data',$data);
        return view('pro_mord');
    }
    public function pro_mors()
    {
        $id=$_GET['id'];
        $ne = Db::name('news')->where(['id'=>$id])->select();
        $data = Db::name('nvg')->select();
        $this->assign('ne',$ne);
        $this->assign('data',$data);
        return view('pro_mors');
    }
}
